package com.xhu.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xhu.common.request.Page;
import com.xhu.common.request.SaleperformContollerGetByNameReq;
import com.xhu.common.vo.SaleperformVo;
import com.xhu.pojo.Dept;
import com.xhu.service.ISaleperformService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/saleperform")
public class SaleperformController extends MyBaseController {

    @Autowired
    private ISaleperformService service;

    @PostMapping("/getAll")
    public String getAllPerform(@RequestBody Page page) {
        IPage<SaleperformVo> result = service.getAll(page.getCurrent(), page.getSize());
        return this.returnPages(result);
    }

    @PostMapping("/getByName")
    public String getByName(@RequestBody SaleperformContollerGetByNameReq req) {
        String name = req.getName();
        IPage<SaleperformVo> res = service.getAllByName(req.getCurrent(), req.getSize(), name);
        return this.returnPages(res);
    }

    @PostMapping("/delete")
    public String deleteById(@RequestBody String req) {
        service.deleteById(this.getSingleStr(req, "id"));

        return this.returnSuccessWithNoData("删除成功");
    }

    @PostMapping("/insert")
    public String insertOne(@RequestBody SaleperformVo vo) {
        service.insertOne(vo);

        return this.returnSuccessWithNoData("添加成功");
    }

    @PostMapping("/getAllDept")
    public String allDept() {
        List<Dept> depts = service.getAllDepts();
        return this.returnSuccessWithData("查询成功", depts);
    }

    @PostMapping("/update")
    public String update(@RequestBody SaleperformVo vo) {
        service.update(vo);

        return this.returnSuccessWithNoData("修改成功");
    }
}
